package com.lollipop.synthential.java8.lambda.syntax.Exercise;

import com.lollipop.synthential.java8.lambda.syntax.data.Person;

import java.util.ArrayList;

/**
 * @Author: J.K
 * @Date: 2021-02-16 15:43
 * @Description:
 */
public class Excise4 {
    public static void main(String[] args) {

        ArrayList<Person> list = new ArrayList();

        list.add(new Person("小明", 10));
        list.add(new Person("小蓝", 12));
        list.add(new Person("小红", 8));
        list.add(new Person("小黄", 16));
        list.add(new Person("小绿", 6));

        // 删除集合中年龄>10的元素

//        Iterator<Person> iterator = list.iterator();
//        while (iterator.hasNext()) {
//            Person ele = iterator.next();
//            if (ele.age>10) {
//                iterator.remove();
//            }
//        }

        // Lambda实现
        list.removeIf(ele -> ele.age > 10);
        System.out.println(list);
    }
}
